<template>
	<view class="u-p-b-30">
		<view class="started-flow-list u-m-t-20" v-for="(item, i) in list" :key="i" @click="toFlow(item)">
			<view class="u-flex u-row-between u-p-30">
				<view class="flow-title">
					{{item.fullName}}
				</view>
				<view>
					{{$u.timeFormat(item.creatorTime, 'yyyy-mm-dd')}}
				</view>
			</view>
			<view class="u-flex u-row-between u-p-l-30 u-p-r-30 u-p-b-30">
				<view class="flow-status">
					{{item.enCode}}
				</view>
				<view :class="$util.getFlowStatus(item.status).color">
					{{$util.getFlowStatus(item.status).text}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentPage: 1,
				list: [],
				total: -1
			}
		},
		methods: {
			toFlow(pItem) {
				// console.log(pItem.status)
				if (pItem.status === 0 || pItem.status === 4) {
					this.$u.route('pages/work/flowchart/dynamic/index', {
						formId: pItem.id,
						id: pItem.flowId,
						title: pItem.fullName
					})
				} else {
					this.$u.route('pages/work/flowchart/dynamic/check', {
						formId: pItem.id,
						id: pItem.flowId,
						stepId: pItem.thisStepId,
						title: pItem.fullName,
						type: pItem.status == 1? 1: 3
					})
				}
			},
			loadData() {
				if(this.total !== this.list.length){
					this.$u.api.getFlowLaunch({
						pageSize: 20,
						currentPage: this.currentPage
					}).then(res => {
						this.total = res.pagination.total
						if (this.currentPage == 1) {
							this.list = res.list
						} else {
							this.list.push(...res.list)
						}
					}).catch(err => {
						console.error(err)
					})
				}
			}
		},
		onShow() {
			this.list = []
			this.loadData()
		},
		onBackPress(options) {
			this.$u.route({
				type: 'tab',
				url: 'pages/work/workbench'
			})
			return true
		},
		onReachBottom() {
			this.currentPage ++
			this.loadData()
		}
	}
</script>

<style lang="scss" scoped>
	.started-flow-list {
		// height: 600rpx;
		background-color: #FFFFFF;
		.flow-title {
			font-weight: bold;
		}

		.flow-status {
			color: #999999;
		}
	}
</style>
